<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>叩丁狼</title>
	<#include "common/header.ftl" >
	<script src="/static/jquery/jquery-form/jquery.form.js" ></script>
	<script src="/static/jquery/jquery-bootstrap/jquery.bootstrap.min.js" ></script>
	<script>
        $(function () {
            $('#pagination').twbsPagination({
                first:'首页',
                prev:'上一页',
                next:'下一页',
                last:'尾页',
                totalPages:${pageInfo.pages} || 1,
                visiblePages:3,
                startPage:${pageInfo.pageNum},
                onPageClick:function (event,page) {
                    $('#currentPage').val(page);//修改表单的当前页
                    $('#searchForm').submit();//提交当前表单
                }
            });

            $.messager.model={
                ok:{text:"确定"},
                cancel:{text:"取消"}
            };
			
			$(".btu-input").click(function () {
			    //清空数据,以免新增时,出现编辑后的回显数据
			    $('#editForm input').val("");
                var json = $(this).data('json');
			    if(json){
			        $('[name=id]').val(json.id);
			        $('[name=name]').val(json.name);
			        $('[name=sn]').val(json.sn);
				}
				$('#myModal').modal("show");
            });

			$('.btu-submit').click(function () {
			    $('#editForm').ajaxSubmit(function (data) {
					if(data.success){
						$.messager.alert('温馨提示','操作成功!  2s后刷新页面');

                        setTimeout(function () {
                            window.location.reload();
                        },2000);
					}
                })
            });
			/*删除操作*/
			$('.btu-delete').click(function () {
			    var url = $(this).data('url');
			    $.messager.confirm("温馨提示",'确定删除该数据吗?',function () {
                    $.get(url,function (data) {
						if(data.success){
						    $.messager.alert('温馨提示','删除成功 2s后刷新页面');
						    setTimeout(function () {
                                window.location.reload();
							},2000)
						}
                    })
                })

            })
        })
	</script>
</head>
<body>
<!--设置用于菜单回显-->
<#assign currentMenu="department">
<div class="container " style="margin-top: 20px">
	<#include "../common/top.ftl" >
	<div class="row">
		<div class="col-sm-3">
			<#include "../common/menu.ftl" >
		</div>
		<div class="col-sm-9">
			<div class="row">
				<div class="col-sm-12">
					<h1 class="page-head-line">部门管理</h1>
				</div>
			</div>
			<!--高级查询--->
			<form class="form-inline" id="searchForm" action="/department/list.do" method="post">
				<#--<input type="hidden" name="currentPage" id="currentPage">-->
				<input id="currentPage" type="hidden" name="currentPage" value="${qo.currentPage}">

			</form>
			<a  class="btn btn-success btu-input">添加</a>

			<table class="table table-striped table-hover" >
				<thead>
				<tr>
					<th>编号</th>
					<th>名称</th>
					<th>编码</th>
					<th>操作</th>
				</tr>
				</thead>
				<#list  pageInfo.list as department>
				<#--<c:forEach items="${pageResult.result}" var="department" varStatus="vs">-->
					<tr>
						<td>${department_index+1}</td>
						<td>${department.name}</td>
						<td>${department.sn}</td>
						<td>
							<a class="btn btn-info btn-xs btu-input" data-json='${(department.jsonString)!}'>
								<span class="glyphicon glyphicon-pencil"></span>编辑
							</a>
						<@shiro.hasPermission name="department:delete">
							<a  class="btn btn-danger btn-xs btu-delete" data-url='/department/delete.do?id=${department.id}'>
								<span class="glyphicon glyphicon-trash"></span>删除
							</a>
						</@shiro.hasPermission>
						</td>
					</tr>
				<#--</c:forEach>-->
				</#list>
			</table>

			<div style="text-align: center;">
				<ul id="pagination" class="pagination"></ul>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">部门编辑</h4>
            </div>
            <div class="modal-body">
			<#--编辑输入框-->
				<form class="form-horizontal" action="/department/saveOrUpdate.do" method="post" id="editForm">
					<input type="hidden"  name="id">
					<div class="form-group" >
						<label for="name" class="col-sm-2 control-label">名称：</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" id="name" name="name"  placeholder="请输入部门名称">
						</div>
					</div>
					<div class="form-group" >
						<label for="sn" class="col-sm-2 control-label">编码：</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" id="sn" name="sn" placeholder="请输入部门编码">
						</div>
					</div>

				</form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btu-submit">确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


</body>
</html>